﻿using System;
using System.Linq;
using CeskyRozhlasWP8.Resources;
using Microsoft.Phone.Scheduler;

namespace CeskyRozhlasWP8.Model
{
    class PlaybackRemindersManager
    {
        public static void AddReminder(DetailedScheduleItem aItem)
        {
            var notifications = ScheduledActionService.GetActions<Reminder>();
            if (notifications.Any(item => item.Name == aItem.Id.ToString()))
            {
                return;
            }
            ScheduledActionService.Add(CreateReminder(aItem));
        }

        private static Reminder CreateReminder(DetailedScheduleItem aItem)
        {
            var reminder = new Reminder(aItem.Id.ToString())
            {
                BeginTime = aItem.StartTime,
                ExpirationTime = aItem.StopTime,
                NavigationUri =
                    new Uri("/RadiostationPage.xaml?stationid=" + aItem.StationId + "&autoPlay=true", UriKind.Relative),
                Title = AppResources.ReminderPlaybackInvitation, //"Přehrát?",
                Content = AppResources.ReminderText + aItem.Title //"Pravé ted' se začíná "
            };
            return reminder;
        }

        public static void RemoveReminder(DetailedScheduleItem aItem)
        {
            ScheduledActionService.Remove(aItem.Id.ToString());
        }
    }
}
